package org.jflame.captcha.creator.factory;

import org.jflame.captcha.creator.CaptchaCreator;
import org.jflame.captcha.creator.TextCaptchaCreator;
import org.jflame.commons.config.ConfigReader;
import org.jflame.commons.config.ConfigKey;

@SuppressWarnings("rawtypes")
public class TextCreatorFactory extends CaptchaCreatorFactory {

    /**
     * 文字生成个数
     */
    public ConfigKey<Integer> KEY_COUNT = new ConfigKey<>(cfgKey("count"));
    /**
     * 随机文字是否生成汉字
     */
    public ConfigKey<Boolean> KEY_HAS_CHINESE = new ConfigKey<>(cfgKey("has_chinese"), false);
    /**
     * 随机文字是否生成数字
     */
    public ConfigKey<Boolean> KEY_HAS_NUMBER = new ConfigKey<>(cfgKey("has_number"), true);
    /**
     * 随机文字是否生成字母
     */
    public ConfigKey<Boolean> KEY_HAS_LETTER = new ConfigKey<>(cfgKey("has_letter"), true);

    @Override
    public CaptchaCreator build(ConfigReader captchaConfig) {
        TextCaptchaCreator textCaptchaCreator = new TextCaptchaCreator(captchaConfig.getBoolean(KEY_HAS_CHINESE),
                captchaConfig.getBoolean(KEY_HAS_NUMBER), captchaConfig.getBoolean(KEY_HAS_LETTER),
                captchaConfig.getInt(KEY_COUNT));
        return textCaptchaCreator;
    }

    @Override
    public String getCaptchaType() {
        return "text";
    }

}
